package utils;

import java.sql.*;

public class JDBCUtils {
    public static Connection getConnection() throws SQLException, ClassNotFoundException{
        Class.forName("com.mysql.cj.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/experiment?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8";
        String username = "root";
        String password = "Wang+001106";
        return DriverManager.getConnection(url,username,password);
    }
    public static void release(Statement stmt, Connection conn){
        if (stmt!=null){
            try {
                stmt.close();
            }catch (SQLException e){
                e.printStackTrace();
            }
        }
        if (conn != null){
            try{
                conn.close();
            }catch (SQLException e){
                e.printStackTrace();
            }
        }
    }
    public static void release(ResultSet rs, Statement stmt, Connection conn){
        if(rs!=null){
            try{
                rs.close();
            }catch (SQLException e){
                e.printStackTrace();
            }
        }
        release(stmt,conn);
    }
}
